package stores

import (
	"jvm/nzpJvm/instructions/base"
	"jvm/nzpJvm/runtime_area"
)

// 将操作数栈中一个引用存入局部变量表指定索引位置
type ASTORE struct{ base.Index8Instruction }
type ASTORE_0 struct{ base.NoOperandsInstruction }
type ASTORE_1 struct{ base.NoOperandsInstruction }
type ASTORE_2 struct{ base.NoOperandsInstruction }
type ASTORE_3 struct{ base.NoOperandsInstruction }

func (self *ASTORE) Execute(frame *runtime_area.Frame) {
	_astore(frame, self.Index)
}

func (self *ASTORE_0) Execute(frame *runtime_area.Frame) {
	_astore(frame, 0)
}

func (self *ASTORE_1) Execute(frame *runtime_area.Frame) {
	_astore(frame, 1)
}

func (self *ASTORE_2) Execute(frame *runtime_area.Frame) {
	_astore(frame, 2)
}

func (self *ASTORE_3) Execute(frame *runtime_area.Frame) {
	_astore(frame, 3)
}

func _astore(frame *runtime_area.Frame, index uint) {
	// 从栈帧的操作数栈中出一个ref值，
	aRef := frame.OperandStack().PopRef()
	// 保存到本地变量表中
	frame.LocalVars().SetRef(index,aRef)
}


